package net.ecpt.clm.rest;

import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import javolution.util.FastMap;

public class RestTest {
    

    /**
     * 获取合同详情,合同费用明细列表
     */
    public static void getClmAgreement() {
	String apiUrl = "getClmAgreementPrice";
	Map<String,Object> params  = FastMap.newInstance();
	params.put("login.username", "admin");
	params.put("login.password", "ecpt123456");
	params.put("id", "10060");
	RestHelper.sendGET(apiUrl,params);
    }

    /**
     * 获取合同列表
     */
    public static void listClmAgreement() {
	String apiUrl = "listClmAgreement";
	Map<String,Object> params  = FastMap.newInstance();
	params.put("login.username", "admin");
	params.put("login.password", "ecpt123456");
	RestHelper.sendGET(apiUrl,params);
    }
    
    /**
     * 接收bms的预估账单,最终账单 生成收款申请单
     * @param args
     */
    public static void createClmCollectionOrder() {
	String apiUrl = "createClmCollectionOrder";
	Map<String,Object> params  = FastMap.newInstance();
	params.put("login.username", "admin");
	params.put("login.password", "ecpt123456");
	
	params.put("collectionCode", "2222222");	//收款编号
	params.put("typeId", "final");	//estimate 预估账单，final最终账单
	params.put("isConfirm", "N");	//确认账单
	params.put("agreementId", "10060");	//系统合同编号
	
	params.put("customerId", ""); //相关客户
	
	params.put("collectionAmount", 20000);  //收款金额
	params.put("collectionPeriod", "6");  //收款账期 
	params.put("billdate", getTimestamp(System.currentTimeMillis()));//单据日期
	params.put("collectionMode", "微信转账"); //收款方式
//	params.put("currencyTypeId", "CNY");	//币种   CNY  USD
//	params.put("rateTypeId", "");  //汇率类型
	params.put("sourceId", ""); //生成来源
	params.put("description", "本次测试收款");//备注
	
	params.put("corpcode", "111");		//财务组织
	params.put("billmaker", "222");	//创建人
	
	JSONArray array = new JSONArray();
	
	JSONObject ob1 = new JSONObject();
	
	ob1.put("scomment", "测试摘要01");//摘要
	ob1.put("objtype", "0");	//往来对象
	ob1.put("customer", "yangpeng01");//客户
	ob1.put("dept", "");	//部门
	ob1.put("psndoc", "");	//业务员
	ob1.put("recaccount", "4062540688526658");//收款银行账户
	ob1.put("prepay", "0");	//0=应收款，1=预收款   收款性质
	ob1.put("currtype", "CNY");	//币种
	ob1.put("rate", 1);	//汇率
	ob1.put("money", 10000);	//金额
	ob1.put("balatype", "银行转账");	//结算方式
	ob1.put("inoutbusiclass", "收支项目");	//往来类型
	
	JSONObject ob2 = new JSONObject();
	ob2.put("scomment", "测试摘要01");
	ob2.put("objtype", "1");
	ob2.put("customer", "");
	ob2.put("dept", "1111");
	ob2.put("psndoc", "");
	ob2.put("recaccount", "4062540688526658");
	ob2.put("prepay", "0");	//0=应收款，1=预收款
	ob2.put("currtype", "CNY");
	ob2.put("rate", 1);
	ob2.put("money", 10000);
	ob2.put("balatype", "银行转账");
	ob2.put("inoutbusiclass", "收支项目");
	
	array.add(ob1);
	array.add(ob2);
	System.out.println(array.toString());
	params.put("itemList", array.toString()); //收款明细,json数据   1项名称  2 单价  3单价单位 4 数量  5 数量单位  6 金额   7 调整   8 小计
	RestHelper.sendPOST(apiUrl,params);
    }

    public static void main(String[] args) {
	System.out.println("start");
//	listClmAgreement();
//	getClmAgreement(); 
	createClmCollectionOrder();
	
	System.out.println("end");
    }
    
    public static String getTimestamp(long time) {
        return new java.sql.Timestamp(time).toString();
    }
}
